const userService = require('../../services/userService');
const articleService = require('../../services/articleService');

const verifyArticleCreate = async (req, res, next) => {
  const { userId } = req.body;
  const users = await userService.getUserById(userId);
  if (!users?.length) {
    const err = new Error(`用户不存在`);
    err.statusCode = 400; // 设置状态码
    next(err); // 传递给错误处理中间件
  }
  next();
}

const verifyArticleDelete = async (req, res, next) => {
  const { id } = req.body;
  const articles = await articleService.getArticleDetail(id);
  if (!articles) {
    const err = new Error(`文章不存在`);
    err.statusCode = 400; // 设置状态码
    next(err); // 传递给错误处理中间件
  }
  next();
}




module.exports = {
  verifyArticleCreate,
  verifyArticleDelete
}